package www.openteam.com.presenter.business;

import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.CustomType;
import www.openteam.com.bean.InsertStatus;
import www.openteam.com.bean.ProductInfo;
import www.openteam.com.contract.business.EditProductInfoContract;
import www.openteam.com.model.business.EditProductInfoModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.business.EditProductInfoFragment;

/**
 * Created by hyd on 2016/10/16.
 */

public class EditProductInfoPresenter extends BasePresenter<EditProductInfoFragment>
        implements EditProductInfoContract.EditProductInfoPresenter {

    @Override
    public HashMap<String, IModel> getiModelMap() {


        return loadModelMap(new EditProductInfoModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("EditProduct", models[0]);
        return hashMap;
    }

    @Override
    public void queryMaterialTypelst() {
        ((EditProductInfoModel) getiModelMap().get("EditProduct"))
                .queryMaterialTypelst(new EditProductInfoModel.EditProductMInfoOnListener() {
                    @Override
                    public void queryMTSuccess(CustomType materialTypelst) {
                        getIView().loadMTData(materialTypelst);

                    }

                    @Override
                    public void queryMTFail(Throwable throwable) {
                        getIView().hideMTData(throwable);
                    }
                });


    }

    @Override
    public void deleteProductInfo(String code) {
        ((EditProductInfoModel) getiModelMap().get("EditProduct"))
                .deleteProductInfo(code, new EditProductInfoModel.EditProductDInfoOnListener() {
                    @Override
                    public void deletePISuccess(InsertStatus insertStatus) {
                        getIView().deletePIData(insertStatus);
                    }

                    @Override
                    public void deletePIFail(Throwable throwable) {
                        getIView().failPIData(throwable);
                    }
                });

    }

    @Override
    public void queryProductInfo(String code, String name, int PageSize) {
        ((EditProductInfoModel) getiModelMap().get("EditProduct"))
                .queryProductInfo(code, name, PageSize, new EditProductInfoModel.EditProductPInfoOnListener() {
                    @Override
                    public void queryPISuccess(ProductInfo productInfo) {
//                        ProductInfo.DataEntity dataEntity = productInfo.getData().get(0);
//                        dataEntity.setCustCode("OpenTeam");
                        getIView().loadPIData(productInfo);
                    }

                    @Override
                    public void queryPIFail(Throwable throwable) {
                        getIView().hidePIData(throwable);
                    }
                });
    }
}
